package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.dto.LoginDto;
import com.itheima.dto.QueryEmpDto;
import com.itheima.pojo.Emp;
import com.itheima.vo.EmpVo;
import com.itheima.vo.ItemVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EmpMapper {

    /**
     * 条件分页查询
     *
     * @param dto
     * @return
     */
    Page<EmpVo> list(QueryEmpDto dto);

    /**
     * 添加员工
     *
     * @param emp
     */
    void insert(Emp emp);

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Select("select * from emp where id=#{id}")
    Emp getById(Integer id);

    /**
     * 修改员工信息
     *
     * @param emp
     */
    void updateById(Emp emp);

    /**
     * @param id
     */
    @Delete("delete from emp where id=#{id}")
    void deleteById(Integer id);

    /**
     * 查询所有
     *
     * @return
     */
    @Select("select * from emp")
    List<Emp> findAll();

    /**
     * 查询员工性别统计
     *
     * @return
     */
    @Select("select if(gender=1,'男性员工', '女性员工') AS name, count(*) AS value from emp group by gender")
    List<ItemVo> getEmpGenderData();


    List<ItemVo> getEmpJobData();

    /**
     * 根据用户名，密码查询
     *
     * @param dto
     * @return
     */
    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp getByUsernameAndPassword(LoginDto dto);

    /**
     * 根据用户名查询
     *
     * @param username
     * @return
     */
    @Select("select * from emp where username=#{username}")
    Emp getByUsername(String username);

    /**
     * 根据部门id删除
     *
     * @param deptId
     */
    @Delete("delete from emp where dept_id=#{deptId}")
    void deleteByDeptId(Integer deptId);
}
